import java.util.Scanner;

public class text_9 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int n1 = scanner.nextInt();
        int a = n;
        int b = n1;
        int c = n%n1;
        while(c!=0){
            a = n1;
            b = c;
            c = a%b;
        }
        System.out.println(b);
    }
}
